package com.dranie.action;

import com.dranie.entity.Order;
import com.dranie.validator.OrderValidator;
import com.jfinal.aop.Before;
import com.jfinal.core.Controller;

/**
 * BlogController 注意：在实际项目中业务与sql需要写在Model中，此demo仅为示意,故将sql写在了Controller中
 */
@Before(com.dranie.interceptor.UserInterceptor.class)
public class OrderController extends Controller {
	public void index() {
		setAttr("orderPage", Order.dao.paginate(getParaToInt(0, 1), 10,
				"select *", "from `order` order by id asc"));
		render("list.html");
	}

	public void add() {
	}

	@Before(OrderValidator.class)
	public void save() {
		getModel(Order.class).save();
		redirect("/admin/order");
	}

	public void edit() {
		setAttr("order", Order.dao.findById(getParaToInt()));
	}

	@Before(OrderValidator.class)
	public void update() {
		getModel(Order.class).update();
        redirect("/admin/order");
	}

	public void delete() {
		Order.dao.deleteById(getParaToInt());
        redirect("/admin/order");
	}
}
